<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
<form class="layui-form">
    <div class="layui-form">

        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" name="auditName" placeholder="请输入姓名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input type="text"lay-verify="required|phone" name="auditPhone" placeholder="请输入电话号码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">个人简介</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" name="auditDescription" placeholder="请输入简介" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作经验</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" name="auditExperience" placeholder="请输入工作经验" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="area-picker">
            <div class="layui-form-label">居住地址</div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="auditProvince" lay-verify="required" class="province-selector" data-value="天津市" lay-filter="province-1">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="auditCity"lay-verify="required" class="city-selector" data-value="天津市" lay-filter="city-1">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="auditArea" lay-verify="required" class="county-selector" data-value="西青区" lay-filter="county-1">
                    <option value="">请选择区</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">身份证照片</label>
            <div class="layui-input-block">
                <input type="file" lay-verify="required" name="auditIdcard" id="fileInput" style="display: none;">
                <button type="button" class="layui-btn" id="selectFileBtn">
                    <i class="layui-icon layui-icon-upload">上传文件</i>
                </button>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitBtn1">提交</button>
            </div>
        </div>
    </div>

</form>
</body>
<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="js/axios.min.js"></script>
<script>
    layui.use(['layer', 'form', 'layarea'], function () {
                var layarea = layui.layarea;
                var form = layui.form;
                var layer = layui.layer;

                layarea.render({
                    elem: '#area-picker',

                    change: function (res) {
                        //选择结果
                        console.log(res);
                    }
                });

                var file = null;

                document.getElementById('selectFileBtn').addEventListener('click', function() {
                    document.getElementById('fileInput').click();
                });


                document.getElementById('fileInput').addEventListener('change', function() {
                    file = this.files[0];


                });

                form.on('submit(submitBtn1)', function (data) {
                    event.preventDefault();

                    data = data.field;
                    // console.log(data)
                    var formDataObj = new FormData();

                    for (var key in data) {
                        formDataObj.append(key, data[key]);

                    }

                    formDataObj.append("auditIdcard", file)


                    axios.post('http://localhost:8080/audit/admit', formDataObj)
                        .then(function(response) {
                            // 请求成功的处理逻辑
                            console.log(response)
                            layer.msg('申请提交成功', {time: 300}, function() {
                                // 关闭表单弹出层
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        })
                        .catch(function(error) {
                            // 请求失败的处理逻辑
                            console.error(error);
                        });

                });

            });
</script>
</html>